package com.df.bpm.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.df.bpm.entity.*;
import com.df.bpm.service.impl.*;
import com.df.common.entity.Pagination;
import com.df.common.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 控制计划控制器
 */
@Slf4j
@Tag(name = "控制计划控制器")
@RequestMapping("/ctrlPlan")
@RequiredArgsConstructor
@RestController
@SaCheckLogin
public class CtrlPlanController {
    private final CpFrequencyServiceImpl cpFrequencyServiceImpl;
    private final CpCapacityServiceImpl cpCapacityServiceImpl;
    private final ReactionPlanServiceImpl reactionPlanServiceImpl;
    private final CtrlPlanServiceImpl ctrlPlanServiceImpl;
    private final RequirementCPServiceImpl requirementCPServiceImpl;

    /**
     * 查询控制计划
     * @param pagination 分页信息
     * @param temp 控制计划线索
     * @return  控制计划列表
     */
    @Operation(summary = "查询控制计划", description = "查询控制计划")
    @GetMapping("")
    @SaIgnore
    public ResponseEntity<?> getCtrlPlan(Pagination pagination, CtrlPlan temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(ctrlPlanServiceImpl.getList4Like(temp)));
        } else {
            return ResponseEntity.ok(ctrlPlanServiceImpl.getList4Like(temp));
        }
    }

    /**
     * 新增控制计划
     * @param temp   控制计划信息
     * @return  新增成功后的控制计划信息
     */
    @Operation(summary = "新增失效模式", description = "新增失效模式")
    @PostMapping("")
    @SaIgnore
    public ResponseEntity<?> newCtrlPlan(@RequestBody CtrlPlan temp) {
        ctrlPlanServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

    /**
     * 关联申请单
     * @param temp   关联关系
     * @return  关联关系
     */
    @Operation(summary = "关联申请单", description = "关联申请单")
    @PostMapping("bindRequirement")
    @SaIgnore
    public ResponseEntity<?> bindRequirement(@RequestBody RequirementCP temp) {
        requirementCPServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

    /**
     * 查询控制频率
     * @param pagination 分页信息
     * @param temp 控制频率线索
     * @return  控制频率列表
     */
    @Operation(summary = "查询控制频率", description = "查询控制频率")
    @GetMapping("cpFrequency")
    @SaIgnore
    public ResponseEntity<?> getCpFrequency(Pagination pagination, CpFrequency temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(cpFrequencyServiceImpl.getList4Like(temp)));
        } else {

            return ResponseEntity.ok(cpFrequencyServiceImpl.getList4Like(temp));
        }
    }

    /**
     * 查询控制容量
     * @param pagination 分页信息
     * @param temp 控制容量线索
     * @return  控制容量列表
     */
    @Operation(summary = "查询控制容量", description = "查询控制容量")
    @GetMapping("cpCapacity")
    @SaIgnore
    public ResponseEntity<?> getCpCapacity(Pagination pagination, CpCapacity temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(cpCapacityServiceImpl.getList4Like(temp)));
        } else {

            return ResponseEntity.ok(cpCapacityServiceImpl.getList4Like(temp));
        }
    }
    /**
     * 新增控制容量
     * @param temp   控制容量
     * @return  新增成功后的控制容量
     */
    @Operation(summary = "新增控制容量", description = "新增控制容量")
    @PostMapping("cpCapacity")
    @SaIgnore
    public ResponseEntity<?> newCpCapacity(@RequestBody CpCapacity temp) {
        cpCapacityServiceImpl.add(temp);
        return ResponseEntity.ok(temp);
    }

    /**
     * 查询反应计划
     * @param pagination 分页信息
     * @param temp 反应计划线索
     * @return  反应计划列表
     */
    @Operation(summary = "查询反应计划", description = "查询反应计划")
    @GetMapping("reactionPlan")
    @SaIgnore
    public ResponseEntity<?> getReactionPlan(Pagination pagination, ReactionPlan temp) {
        if (CommonUtils.varIsNotBlank(pagination.getPageNum(), pagination.getPageSize())) {
            PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
            return ResponseEntity.ok(new PageInfo<>(reactionPlanServiceImpl.getList4Like(temp)));
        } else {

            return ResponseEntity.ok(reactionPlanServiceImpl.getList4Like(temp));
        }
    }

}
